// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import "fmt"

// 具有两个泛型类型的泛型结构
type GMap[K, V any] struct {
	Key   K
	Value V
}

func GeneFunc[K comparable, V any](m map[K]V) []*GMap[K, V] {
	//定义一个GMap类型的切片，传递K、V类型参数
	g := make([]*GMap[K, V], len(m))
	i := 0
	for k, v := range m {
		// 使用 new 关键字创建值
		newGMap := new(GMap[K, V])
		newGMap.Key = k
		newGMap.Value = v
		g[i] = newGMap
		i++
	}
	return g
}

func main() {
	type K string
	type V any
	m := map[K]V{"a": "b"}
	res := GeneFunc(m)
	fmt.Println(res[0])
}

//$ go run generics4.go
//&{a b}
